package com.esun.payment_api.service.impl;

import com.esun.payment_api.bean.SumDkReceiveMoneyBean;
import com.esun.payment_api.dao.FkDraftDao;
import com.esun.payment_api.dao.FkDraftDetail;
import com.esun.payment_api.domain.FkDraft;
import com.esun.payment_api.domain.User;
import com.esun.payment_api.dto.FkDraftQueryParam;
import com.esun.payment_api.dto.PInvInsParam;
import com.esun.payment_api.dto.ProcessApprovalParam;
import com.esun.payment_api.dto.SubmitApprovalParam;
import com.esun.payment_api.mapper.FkDraftMapper;
import com.esun.payment_api.service.FkDraftService;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FkDraftServiceImpl implements FkDraftService {

    @Resource
    private FkDraftMapper fkDraftMapper;

    @Override
    public int deleteById(Integer id) {
        return fkDraftMapper.deleteById(id);
    }

    @Override
    public void deleteByIdStr(PInvInsParam param) {
        fkDraftMapper.pFkDelete(param);
    }

    @Override
    public int insertReturnId(FkDraft fkDraft) {
        return fkDraftMapper.insertReturnId(fkDraft);
    }

    @Override
    public FkDraft selectByPrimaryKey(Integer id) {
        return fkDraftMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(FkDraft fkDraft) {
        return fkDraftMapper.updateByPrimaryKeySelective(fkDraft);
    }

    @Override
    public FkDraftDetail getFkDetail(User user, Integer id) {
        return fkDraftMapper.getFkDetail(user.getId(), id);
    }

    @Override
    public List<FkDraftDao> getListByType(FkDraftQueryParam queryParam, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        return fkDraftMapper.getListByType(queryParam);
    }

    @Override
    public SumDkReceiveMoneyBean getSumMoneyBySearch(FkDraftQueryParam queryParam) {
        return fkDraftMapper.getSumMoneyBySearch(queryParam);
    }

    @Override
    public void fkSubmitApproval(SubmitApprovalParam param) {
        String flowTypeName = "汇票付款流程";
        fkDraftMapper.fkSubmitApproval(param.getCoId(), param.getUuid(), param.getFkId(), param.getUserId(), param.getDeptId(), flowTypeName);
    }

    @Override
    public void fkResubmitApproval(SubmitApprovalParam param) {
        String flowTypeName = "汇票付款流程";
        fkDraftMapper.fkResubmitApproval(param.getCoId(), param.getUuid(), param.getFkId(), param.getUserId(), param.getDeptId(), flowTypeName);
    }

    @Override
    public void fkProcessApproval(ProcessApprovalParam param) {
        fkDraftMapper.fkProcessApproval(param.getStatus(), param.getFlowId(), param.getFlowNotes(), param.getUserId(), param.getFkId());
    }

    @Override
    public String checkFkSubmit(Integer id) {
        return fkDraftMapper.checkFkSubmit(id);
    }
}
